package com.jarhow.gojekhook;

import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager;
import android.app.Application;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;

import com.jarhow.gojekhook.Utils.AbstractHook;
import com.jarhow.gojekhook.Utils.HookBundle;
import com.jarhow.gojekhook.Utils.HookPoint;
import com.jarhow.gojekhook.Utils.HookWebview;
import com.jarhow.gojekhook.Utils.HookgetIntent;
import com.jarhow.gojekhook.Utils.Xlog;
import com.jarhow.gojekhook.Utils.XposedUtils;
import com.jarhow.gojekhook.bbk.HookCheck;
import com.jarhow.gojekhook.bbk.HookloadUrl;
import com.jarhow.gojekhook.eleme.HookAppUCWeb;
import com.jarhow.gojekhook.huawei.market.HookDecrypt;
import com.jarhow.gojekhook.huawei.market.HookHuaweiHealth;
import com.jarhow.gojekhook.huawei.market.HookWhiteList;
import com.jarhow.gojekhook.pdd.HookPddAuth;
import com.jarhow.gojekhook.pdd.Hookhotfix;
import com.jarhow.gojekhook.pdd.Hooksentive;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import dalvik.system.DexClassLoader;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class HookGojek implements IXposedHookLoadPackage {
    public static Context MyContext;
    public static HookPoint hookPoint;
    public static Class SingleWebview;
    public static Class Threesd;
    public static Class CrossPlatformActivity;
    public static String Method1 = "com_ss_android_ugc_aweme_crossplatform_platform_webview_SingleWebView_com_ss_android_ugc_tiktok_security_lancet_web_SecLinkLancet_loadUrl";
    public static String Method2 = "SingleWebView__loadUrl$___twin___";
    public static String Method3 = "beforeLoadUrl";
    private static ClassLoader cl;
    private static ClassLoader Systemcl;


//    private void invoke(Class bin, String Method, Objects[] params) {
//        XposedHelpers.findAndHookMethod(bin, "build", new XC_MethodHook() {
//            @Override
//            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
//                super.beforeHookedMethod(param);
//                try {
//                    List interceptors = (List) XposedHelpers.getObjectField(param.thisObject, "networkInterceptors");
////                    interceptors.add(getHttpLoggingInterceptor());
////                    XposedBridge.log("invoke Success!!!" + interceptors.toString());
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                super.afterHookedMethod(param);
//                try {
//                    List interceptors = (List) XposedHelpers.getObjectField(param.thisObject, "networkInterceptors");
////                    interceptors.add(getHttpLoggingInterceptor());
//                    XposedBridge.log("invoke Success!!!" + interceptors.toString());
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        });
//    }

    //    private Object InitInterceptor(ClassLoader cl) throws InstantiationError, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassCastException{
//        try{
//            Class<?> mHttpLoggingInterceptor = Class.forName("okhttp3.logging.HttpLoggingInterceptor",true,cl);
//            Class<?> mLoggerClass = Class.forName("okhttp3.logging.HttpLoggingInterceptor$Logger",true,cl);
//            if(mHttpLoggingInterceptor !=null && mLoggerClass !=null){
//
//                Object logger = Proxy.newProxyInstance(cl, new Class[]{mLoggerClass}, new InvocationHandler() {
//                    @Override
//                    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
//                        XposedBridge.log("this is what I want!!!:" + (String)objects[0]);
//                        return null;
//                    }
//                });
//
//                Object loggingInterceptor = mHttpLoggingInterceptor.getConstructor(mLoggerClass).newInstance(logger);
//
//                Object level = cl.loadClass("okhttp3.logging.HttpLoggingInterceptor$Level").getEnumConstants()[3];
//
//                XposedHelpers.findMethodBestMatch(mHttpLoggingInterceptor,"setLevel",level.getClass()).invoke(loggingInterceptor,level);
//                XposedBridge.log("设置成功！！！！");
//                return loggingInterceptor;
//
//            }
//        }
//        catch (Exception e)
//        {
//            e.printStackTrace();
//        }
//        return null;
//    }
    public void HookPinduoduo(ClassLoader cl) {

        AbstractHook myhook;
        myhook = new Hooksentive();
        myhook.setClassLoader(cl);
        myhook.doHook();

        myhook = new HookPddAuth();
        myhook.setClassLoader(cl);
        myhook.doHook();

        myhook = new HookDecrypt();
        myhook.setClassLoader(cl);
        myhook.doHook();

        myhook = new HookBundle();
        myhook.setClassLoader(cl);
        myhook.doHook();

        myhook = new Hookhotfix();
        myhook.setClassLoader(cl);
        myhook.doHook();

        try {
            final Class<?> logger = XposedHelpers.findClass("com.xunmeng.pinduoduo.alive.strategy.init.adapterImpl.s", cl);
            for (Method m : logger.getDeclaredMethods()) {
                if (!m.getParameterTypes().equals(new Object[]{String.class, Throwable.class})) {
                    XposedBridge.hookMethod(m, new XC_MethodHook() {
                        @Override
                        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                            super.beforeHookedMethod(param);
                            Xlog.d("Hook PddLogger " + m.getName(), (String) param.args[0] + (String) param.args[1]);
                        }
                    });
                } else {
                    XposedBridge.hookMethod(m, new XC_MethodHook() {
                        @Override
                        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                            super.beforeHookedMethod(param);
                            Xlog.d("Hook PddLogger " + m.getName(), (String) param.args[0]);
                        }
                    });
                }
            }
        } catch (Exception e) {
            Xlog.e(e.toString());
        }

//            com.xunmeng.pinduoduo.lifecycle.proguard.c.b


//        myhook = new HookPddAuth();
//        myhook.setClassLoader(cl);
//        myhook.doHook();

        try {
            final Class<?> pdd = XposedHelpers.findClass("android.app.PddActivityThread", cl);
            Method get = pdd.getDeclaredMethod("currentApplication");
            final Application[] app = {new Application()};
            XposedBridge.hookMethod(get, new XC_MethodHook() {
                @Override
                protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                    super.afterHookedMethod(param);
                    app[0] = (Application) param.getResult();
                }
            });


//            final Class<?> auth = XposedHelpers.findClass("com.xunmeng.pinduoduo.lifecycle.service.PDDAuthService",cl);
//            Object PDDAuth = auth.newInstance();
//            Method c = auth.getDeclaredMethod("c");
//            c.setAccessible(true);
//            Class<?> a = cl.loadClass("");


//                Constructor aa = autha.getDeclaredConstructor(Context.class);
//                Object a = aa.newInstance(app[0]);
            final Class<?> Bundle = XposedHelpers.findClass("android.os.Bundle", cl);
            Parcel ob = Parcel.obtain();
            AccountAuthenticatorResponse test = new AccountAuthenticatorResponse(ob);
            Intent intent = new Intent();
            // 重置PIN
            intent.setComponent(new ComponentName(
                    "com.android.settings",
                    "com.android.settings.ChooseLockPassword"
            ));
            intent.setAction(Intent.ACTION_RUN);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra("confirm_credentials", false);
            final Bundle bundle = new Bundle();
            bundle.putParcelable(AccountManager.KEY_INTENT, intent);
            String[] b = {"test3", "test4"};

//                add.invoke(a,test,"test","test2",b,bundle);


//            Log.v(TAG, "addAccount"+bundle);


//            final Class<?> tool = XposedHelpers.findClass("com.xunmeng.pinduoduo.android_pull_ability.pullstartup.b",cl);
//            Object j = tool.newInstance();
////            Method b = tool.getDeclaredMethod("b");
//            Method make = tool.getDeclaredMethod("makeBundle",Bundle.class);
//            make.invoke(j,new Intent());
//
////                final Class<?> nativeitf = XposedHelpers.findClass("com.xunmeng.pinduoduo.lifecycle.nativeitf.a",cl);
//
////            Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","zdNr1Jq1trr-b_0TxId3B_V-306eHw4pYolG2CG7_LvcsH2nLd6KeSidJqQMweM1CGvAV9nr5DWow2Q3-CGS2VYx"));          //ab_support_start_pull_special_activity_5790
////            Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","GSxzGUrKWb8k2q5F9pMo1uUQKVVQLQXDZDYz-FY8MxzFI-Fr2KmOt5_kdhgH9Ot1BhhNwPa1H285f4F1wWy66XLvhpi5LRKDRQedKQ8U-0YmDWbVXZL4o9ipzlABoQDWzlJAhuQ-di525Y6xZ1ax6cihVGDsVLCwYBs_yfcDOUXdTYrOOU3RGzN0"));//com.xunmeng.pinduoduo.android_pull_ability_impl_interface.utils.AlivePullStartUpInterfUtils
////            Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","BlwPqGLRoQptg_EhZbpDwDyoZ3yOzgm0R5jqdR-V"));//getAlivePullStartUp
//
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","JYZQLezDZFAz+A88MyzFUnNL2BeOt+/kdqkHhYB1EiN+wPKDGBE+ddBgy2Gi9bLvnGGtM06MRYWEIgwS9wE7DyTrCw2kvTfsigA="));      //pinduoduo_Android.pa_lifecycle_sync_period_59000
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","S08w2loQOCPNUJP+3i65yJ4epOrGhQA="));  // PDDSyncService
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","jCALUmZd-y-3_ozTvDuxL2-Zc9eXInBD9F01BZ_BTaTP6D2tz_MNvr_Rs3p4hLI0ICZ11IOtZ5_xmnSwTej9RYOVZOEfyKYZ"));  //PDDSyncService#janusRequestSync fail, exception
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","NRoNxAZxU71S2dODCpU6dHh1zVLu5n7VnXOnNCOAdAA"));   //not suitable version
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","tBz9T_-IYAA"));   //comp
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","oCn041iq1W8DqNGFkBttn3owaR19"));  //invoke plugin
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","-esdYeB9wFS3WD2pyIC0QZn7R4Oc"));  //JanusStrategy
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","2ngXNcVgdn_Dq7DPwIqDoU06hsF0q0sqBTbqPLsE0D5h-9zstTLW"));      //invoke_plugin_method_fail
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","YQCz3wyiakDqQXSWewA"));                                                       //new_task
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","_ip_vOnIsrNQ6iNpi2BkEwbJAwA"));                                               //targetIntent
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","pmXEjJhonBIyUGhm2R-oWF6p2winQYjLUAA"));                                       //alivePullStartUp
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","RxOOfn-QBmMD_SM7HozaSknS_YSo03MHo8bW"));                                      //addAccountOptions
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","2nMcMt14fUv3vYr1wpCZvUk-ivBFhFMyDC7yC7UK1xVK9Mv7tSrOEQA"));                   //bind_service_pull_activity
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","UC9d8o_g8n7CHZ6jyHmFb9KNeVVwenHboHp-sineoA9asDlQkGl8Gt74FlU_25NC7c4kzBsO"));  //com.xunmeng.pinduoduo.pull_activity
        } catch (Exception e) {
            e.printStackTrace();
        }

        XposedBridge.hookAllMethods(ClassLoader.class, "loadClass", new XC_MethodHook() {
            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                if (param.hasThrowable()) return;
                if (param.args.length != 1) return;

                final Class<?> cls = (Class<?>) param.getResult();
                String name = cls.getName();

                Xlog.e("Hook Pddmw1", name);
//                    {
//                        if (name.contains("com.xunmeng.pinduoduo.android_pull_ability_comp.pullstartup.a")){
//                            AbstractHook myHook2 = new Hookmw1();
//                            myHook2.setClassLoader(cl);
//                            myHook2.doHook();
//                        }
//                    }
            }
        });

        try {
            final Class<?> tool = XposedHelpers.findClass("com.xunmeng.pinduoduo.lifecycle.proguard.c", cl);
            Method c = tool.getDeclaredMethod("c", String.class);
////                final Class<?> nativeitf = XposedHelpers.findClass("com.xunmeng.pinduoduo.lifecycle.nativeitf.a",cl);
//
            Xlog.d("Hook PddDecrypt", (String) c.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c", "pmXEjJhonBIyUGhm2R-oWF6p2winQYjLUAA"));          //ab_support_start_pull_special_activity_5790
//            Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","GSxzGUrKWb8k2q5F9pMo1uUQKVVQLQXDZDYz-FY8MxzFI-Fr2KmOt5_kdhgH9Ot1BhhNwPa1H285f4F1wWy66XLvhpi5LRKDRQedKQ8U-0YmDWbVXZL4o9ipzlABoQDWzlJAhuQ-di525Y6xZ1ax6cihVGDsVLCwYBs_yfcDOUXdTYrOOU3RGzN0"));//com.xunmeng.pinduoduo.android_pull_ability_impl_interface.utils.AlivePullStartUpInterfUtils
//            Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","BlwPqGLRoQptg_EhZbpDwDyoZ3yOzgm0R5jqdR-V"));//getAlivePullStartUp
//
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","JYZQLezDZFAz+A88MyzFUnNL2BeOt+/kdqkHhYB1EiN+wPKDGBE+ddBgy2Gi9bLvnGGtM06MRYWEIgwS9wE7DyTrCw2kvTfsigA="));      //pinduoduo_Android.pa_lifecycle_sync_period_59000
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","S08w2loQOCPNUJP+3i65yJ4epOrGhQA="));  // PDDSyncService
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","jCALUmZd-y-3_ozTvDuxL2-Zc9eXInBD9F01BZ_BTaTP6D2tz_MNvr_Rs3p4hLI0ICZ11IOtZ5_xmnSwTej9RYOVZOEfyKYZ"));  //PDDSyncService#janusRequestSync fail, exception
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","NRoNxAZxU71S2dODCpU6dHh1zVLu5n7VnXOnNCOAdAA"));   //not suitable version
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","tBz9T_-IYAA"));   //comp
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","oCn041iq1W8DqNGFkBttn3owaR19"));  //invoke plugin
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","-esdYeB9wFS3WD2pyIC0QZn7R4Oc"));  //JanusStrategy
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","2ngXNcVgdn_Dq7DPwIqDoU06hsF0q0sqBTbqPLsE0D5h-9zstTLW"));      //invoke_plugin_method_fail
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","YQCz3wyiakDqQXSWewA"));                                                       //new_task
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","_ip_vOnIsrNQ6iNpi2BkEwbJAwA"));                                               //targetIntent
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","pmXEjJhonBIyUGhm2R-oWF6p2winQYjLUAA"));                                       //alivePullStartUp
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","RxOOfn-QBmMD_SM7HozaSknS_YSo03MHo8bW"));                                      //addAccountOptions
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","2nMcMt14fUv3vYr1wpCZvUk-ivBFhFMyDC7yC7UK1xVK9Mv7tSrOEQA"));                   //bind_service_pull_activity
////                Xlog.d("Hook PddDecrypt", (String) b.invoke("com.xunmeng.pinduoduo.lifecycle.proguard.c","UC9d8o_g8n7CHZ6jyHmFb9KNeVVwenHboHp-sineoA9asDlQkGl8Gt74FlU_25NC7c4kzBsO"));  //com.xunmeng.pinduoduo.pull_activity
//        }catch (Exception e){
//            Xlog.w("Hook PddDecrypt",e.toString());
//        }

//            myhook = new Hookmw1();
//            myhook.setClassLoader(cl);
//            myhook.doHook();
//            myhook = new HookIntent();
//            myhook.setClassLoader(cl);
//            myhook.doHook();
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }

    public void HookHuawei(ClassLoader cl) {
        Xlog.d("Hook Huawei", "classloader is!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:" + cl.getClass().getName());
//        myHook.setClassLoader(cl);
//        myHook.doHook();

        XposedBridge.hookAllMethods(ClassLoader.class, "loadClass", new XC_MethodHook() {
            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                if (param.hasThrowable()) return;
                if (param.args.length != 1) return;

                final Class<?> cls = (Class<?>) param.getResult();
                try {
                    String name = cls.getName();
                    if (name.contains("com.huawei.appgallery.agwebview.whitelist.d")) {
                        AbstractHook myHook = new HookWhiteList();
                        myHook.setClassLoader(cl);
                        myHook.setTag("Hook HuaweiWhiteList");
                        myHook.doHook();
                    }
                    Xlog.d("Hook Huawei", name);
                } catch (Exception e) {

                }

//                    {
//                        if (name.contains("com.xunmeng.pinduoduo.android_pull_ability_comp.pullstartup.a")){
//                            AbstractHook myHook2 = new Hookmw1();
//                            myHook2.setClassLoader(cl);
//                            myHook2.doHook();
//                        }
//                    }
            }
        });


        AbstractHook myHook = new HookWhiteList();
        myHook.setClassLoader(cl);
        myHook.setTag("Hook HuaweiWhiteList");
        myHook.doHook();

    }

    public void hookbbk(ClassLoader cl){
        Xlog.d("Hook bbk", "classloader is!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:" + cl.getClass().getName());
        AbstractHook bbkhook;
        bbkhook = new HookloadUrl();
        bbkhook.setTag("Hook bbk");
        bbkhook.setClassLoader(cl);
        bbkhook.doHook();
        bbkhook = new HookCheck();
        bbkhook.setTag("Hook bbk");
        bbkhook.setClassLoader(cl);
        bbkhook.doHook();

    }

    private void hookeleme(ClassLoader cl) {
//        Xlog.d("Hook eleme", "classloader is!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:" + cl.getClass().getName());
        AbstractHook elemehook;
        elemehook = new HookAppUCWeb();
        elemehook.setTag("HookEleme");
        elemehook.setClassLoader(cl);
        elemehook.doHook();
    }

    private void hookCommonFuncWithPackageName(ClassLoader cl) {
//        Xlog.d("HookCommon", "classloader is!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:" + cl.getClass().getName());

        XposedBridge.hookAllMethods(ClassLoader.class, "loadClass", new XC_MethodHook() {
            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                if (param.hasThrowable()) return;
                final Class<?> cls = (Class<?>) param.getResult();
                try {
                    String name = cls.getName();
                    if(name.contains("BridgeEngine") || name.contains("JsBridge") || name.contains("Logger")) {
                        Xlog.d("HookEleme", "Load Class is:" + name);
                    }
                    if (name.equals("com.uc.webview.export.WebView")) {
                        Xlog.d("HookEleme", "Yes,it is what I need:"+name);
                        XposedHelpers.findAndHookMethod(cls, "addJavascriptInterface", java.lang.Object.class, java.lang.String.class, new XC_MethodHook() {
                            @Override
                            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                                super.beforeHookedMethod(param);
                            }
                            @Override
                            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                                super.afterHookedMethod(param);
                                String name = (String) param.args[1];
                                Object obj = (Object) param.args[0];

                                Xlog.e("HookWebView","UCWebView addJavaScriptInterface is :"+ name);
                                Xlog.e("HookWebView","UCWebView addJavaScriptInterface is :"+ obj.getClass().getName());
                            }
                        });

                        XposedHelpers.findAndHookMethod(cls, "loadUrl", java.lang.Object.class, java.lang.String.class, new XC_MethodHook() {
                            @Override
                            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                                super.beforeHookedMethod(param);
                            }
                            @Override
                            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                                super.afterHookedMethod(param);
                                String url = (String) param.args[0];

                                Xlog.e("HookWebView","UCWebView loadUrl is :"+url);
                                XposedUtils.printCallers("HooKWebView");
                            }
                        });
                    }

                    if (name.contains("android.taobao.windvane.jsbridge.WVBridgeEngine")){
                        XposedHelpers.findAndHookMethod( cls,"nativeCall", java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, new XC_MethodHook() {
                            @Override
                            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                                super.afterHookedMethod(param);
                                Xlog.d("HookJsBridge","nativeCall param1:{"+(String)param.args[0]+"}");
                                Xlog.d("HookJsBridge","nativeCall param2:{"+(String)param.args[1]+"}");
                                Xlog.d("HookJsBridge","nativeCall param3:{"+(String)param.args[2]+"}");
                                Xlog.d("HookJsBridge","nativeCall param4:{"+(String)param.args[3]+"}");

                            }
                        });
                    }

                    if (name.contains("com.alibaba.ut.comm.JsBridge")){
                        XposedHelpers.findAndHookMethod( cls, "CALL", java.lang.String.class, new XC_MethodHook() {
                            @Override
                            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                                super.afterHookedMethod(param);
                                Xlog.d("HookJsBridge","CALL params:{" + (String)param.args[0] + "}");
                            }
                        });


                    }
//                    Xlog.d("HookEleme", name);
                } catch (Exception e) {
                }

//                    {
//                        if (name.contains("com.xunmeng.pinduoduo.android_pull_ability_comp.pullstartup.a")){
//                            AbstractHook myHook2 = new Hookmw1();
//                            myHook2.setClassLoader(cl);
//                            myHook2.doHook();
//                        }
//                    }
            }
        });

//        AbstractHook CommonFunchook;
//        CommonFunchook = new HookWebview();
//        CommonFunchook.setTag("HookWebView");
//        CommonFunchook.setClassLoader(cl);
//        CommonFunchook.doHook();
//        AbstractHook CommonFunchook2;
//        CommonFunchook2 = new HookgetIntent();
//        CommonFunchook2.setTag("HookIntent");
//        CommonFunchook2.setClassLoader(cl);
//        CommonFunchook2.doHook();
    }



    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        if(lpparam.processName.contains("me.ele")||lpparam.processName.contains("com.ss.android.article")||lpparam.processName.contains("com.xingin.xhs")){
            XposedHelpers.findAndHookMethod(Application.class, "attach", Context.class, new XC_MethodHook(){
                            @Override
                            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                                ClassLoader cl = ((Context) param.args[0]).getClassLoader();
                                //cl.loadclass("className")找其他类
                                //Class.forName("className",true,cl)
                                Class<?> hookclass = null;
                                Class<?> hookclass2 = null;
                                try {
                                    hookclass = cl.loadClass("com.alibaba.ut.comm.JsBridge");
                                    hookclass2 = cl.loadClass("android.taobao.windvane.jsbridge.WVBridgeEngine");

                                } catch (Exception e) {
                                    Xlog.e("MutiDex", "寻找com.alibaba.ut.comm.JsBridge失败", e);
                                    return;
                                }
                                Xlog.e("MutiDex", "寻找com.alibaba.ut.comm.JsBridge成功");

                                XposedHelpers.findAndHookMethod(
                                        hookclass,
                                        "CALL",//方法名称
                                        String.class,//参数列表
                                        new XC_MethodHook(){
                                            @Override
                                            protected void beforeHookedMethod(MethodHookParam param) {
                                                //Hook自定义功能
                                                Xlog.e("HookEleme","Find Param:"+(String)param.args[0]);
                                            }
                                            });

                                XposedHelpers.findAndHookMethod(
                                        hookclass2,
                                        "nativeCall",//方法名称
                                        String.class,
                                        String.class,
                                        String.class,
                                        String.class,
                                        //参数列表
                                        new XC_MethodHook(){
                                            @Override
                                            protected void beforeHookedMethod(MethodHookParam param) {
                                                //Hook自定义功能
                                                Xlog.d("HookEleme","nativeCall param1:{"+(String)param.args[0]+"}");
                                                Xlog.d("HookEleme","nativeCall param2:{"+(String)param.args[1]+"}");
                                                Xlog.d("HookEleme","nativeCall param3:{"+(String)param.args[2]+"}");
                                                Xlog.d("HookEleme","nativeCall param4:{"+(String)param.args[3]+"}");
                                            }
                                        });

                            }

            });


            hookCommonFuncWithPackageName(cl);


        }
        if(lpparam.processName.contains("me.ele")){
            hookeleme(cl);
        }


//        if (lpparam.processName.contains("com.WTikTok")) {
//            cl = lpparam.classLoader;
//            AbstractHook myHook = new HookWebview();
//            myHook.setClassLoader(cl);
//            myHook.doHook();
//        }
//        if (lpparam.processName.contains("com.huawei.health")) {
//            cl = lpparam.classLoader;
//
//            AbstractHook myHook = new HookHuaweiHealth();
//            myHook.setClassLoader(cl);
//            myHook.setTag("Hook Health");
//            myHook.doHook();
//
//        }

//        if (lpparam.processName.contains("com.huawei.")) {
//            cl = lpparam.classLoader;
//
//            AbstractHook myHook = new HookHuaweiHealth();
//            myHook.setClassLoader(cl);
//            myHook.setTag("Hook Health");
//            myHook.doHook();
//            AbstractHook myHook = new HookWebview();
//            myHook.setClassLoader(cl);
//            myHook.setTag("Hook HuaweiFast");
//            myHook.doHook();
//        }
//        if(lpparam.processName.contains("com.bbk.appstore")){
//            cl = lpparam.classLoader;
//            hookbbk(cl);
//        }
//        if(lpparam.processName.contains("me.ele")){
//            cl = lpparam.classLoader;
//            hookeleme(cl);
//        }


//        if (lpparam.packageName.contains("com.zhiliao.musically.")){
//            XposedHelpers.findAndHookMethod("com.ss.android.ugc.aweme.crossplatform.activity.CrossPlatformActivity", lpparam.classLoader, "onCreate",Bundle.class, new XC_MethodHook() {
//                @Override
//                protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
//                    super.beforeHookedMethod(param);
//                    Bundle bundle = (Bundle) param.args[0];
//                    XposedBridge.log("This is the Intent :" + bundle);
//                }
//            });
//            Class SingleWebView= Class.forName("com.ss.android.ugc.aweme.crossplatform.platform.webview.SingleWebView",true,lpparam.classLoader);
//            XposedHelpers.findAndHookMethod("com.ss.android.ugc.aweme.crossplatform.platform.webview.SingleWebView", lpparam.classLoader, Method1, SingleWebView.getClass(), String.class, new XC_MethodHook() {
//                @Override
//                protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
//                    super.beforeHookedMethod(param);
//                    String url = (String) param.args[0];
//                    XposedBridge.log("This is SingleWebView's loading Url" + url);
//                }
//            });
//            }
    }



    public void hookApplication() {

        XposedHelpers.findAndHookMethod(Application.class, "attach", Context.class, new XC_MethodHook() {
            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                cl = ((Context) param.args[0]).getClassLoader();
                if (MyContext == null) {
                    MyContext = (Context) param.thisObject;
                }
            }
        });

//                    AbstractHook myHook;
//                    myHook = new hookCrossPlatformActivity();
//                    myHook.setClassLoader(cl);
//                    myHook.doHook();
//
//                    myHook = new hookSmartIntent();
//                    myHook.setClassLoader(cl);
//                    myHook.doHook();
//
//                    myHook = new hookX3sg();
//                    myHook.setClassLoader(cl);
//                    myHook.doHook();
//
//                    myHook = new hookXFYA();
//                    myHook.setClassLoader(cl);
//                    myHook.doHook();
//
//                    myHook = new hookSecLinkManger();
//                    myHook.setClassLoader(cl);
//                    myHook.doHook();
//
//                    myHook = new hookFX7();
//                    myHook.setClassLoader(cl);
//                    myHook.doHook();
//
//                    myHook = new hookSingleWebView();
//                    myHook.setClassLoader(cl);
//                    myHook.doHook();

//                    myHook = new HookgetIntent();
//                    myHook.setClassLoader(cl);
//                    myHook.doHook();
//                    XposedHelpers.findAndHookMethod()
//                    XposedHelpers.findAndHookMethod("dalvik.system.DexFile", clzLd, "loadClass",
//                            String.class, "java.lang.ClassLoader", new XC_MethodHook() {
//                                @Override
//                                protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                                    String className = (String) param.args[0];
//                                    Object result = param.getResult();
//                                    if (result != null && result instanceof Class) {
//                                        if ("com.alipay.mobile.nebulauc.impl.UCWebViewClient".equals(className)) {
//                                            LogUtil.debug(LOG_BILL_CLICK_LOG,"Load class:" + ((Class) result).getName());
//                                            // hookLoadWebViewClient(((Class) result).getClassLoader());
//                                        } else if ("com.alipay.mobile.bill.list.ui.BillListActivity".equals(className)) {
//                                            LogUtil.debug(LOG_BILL_CLICK_LOG,"Load class:" + ((Class) result).getName());
//                                            hookBillList(((Class) result).getClassLoader());
//                                        }
//                                    }
//                                }
//                            });
//                    //这个和上面不会同时发生
//                    if (XposedHelpers.findClassIfExists("com.alipay.mobile.nebulauc.impl.UCWebViewClient", clzLd) != null) {
//                        LogUtil.debug(LOG_BILL_CLICK_LOG,"Hook class:" + "com.alipay.mobile.nebulauc.impl.UCWebViewClient");
//                        // hookLoadWebViewClient(classLoader);
//                    }
//                    if (XposedHelpers.findClassIfExists("com.alipay.mobile.bill.list.ui.BillListActivity", clzLd) != null) {
//                        LogUtil.debug(LOG_BILL_CLICK_LOG,"Hook class:" + "com.alipay.mobile.bill.list.ui.BillListActivity");
//                        hookBillList(clzLd);
//                    }
//                    myHook = new HookloadUrl();
//                    myHook.setClassLoader(cl);
//                    myHook.doHook();

//                    myHook = new HookCheck();
//                    myHook.setClassLoader(cl);
//                    myHook.doHook();

//                    HookAppsFlyer myHook2 = new HookAppsFlyer();
//                    myHook2.setClassLoader(cl);
//                    myHook2.doHook();
//                    myHook2.doHookClass();

//                    HookWebView myHook3 = new HookWebView();
//                    myHook3.setClassLoader(cl);
//                    myHook3.doHook();

//                    HookWebViewClient myHook4 = new HookWebViewClient();
//                    myHook4.setClassLoader(cl);
//                    myHook4.doHook();

//                    myHook = new HookLogger();
//                    myHook.setClassLoader(cl);
//                    myHook.doHook();

//                    myHook = new HookDecrypt();
//                    myHook.setClassLoader(cl);
//                    myHook.doHook();


//                    Xlog.e("HookMain","Find com.ss.android.ugc")
    }

}
